from config.db import REDIS_CONFIG
from redis import Redis


class DuplicateRemoval:
    def __init__(self, app_code):
        self.redis = Redis(host=REDIS_CONFIG['host'], port=REDIS_CONFIG['port'])
        self.app_code = app_code

    def check_same_url(self, url):
        return self.redis.sismember(self.app_code, url)

    def check_same_url_save(self, url):
        if self.redis.sismember(self.app_code, url):
            return True
        else:
            self.redis.sadd(self.app_code, url)
            return False
